package com.ewanghuiju.app.ui.main.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.model.bean.response.IntenestTagResponBean;
import com.ewanghuiju.app.test.bean.TestBean;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;

import java.util.List;

import androidx.cardview.widget.CardView;
import androidx.core.content.ContextCompat;

/**
 * @author sj  qq:751943509
 * @class describe
 * @time 2020/2/26
 */
public class MyFlowTagAdapter extends TagAdapter {
    private  Context  mContext;
    private int mType;
    public MyFlowTagAdapter(List datas, Context  context,int type) {
        super(datas);
        this.mContext = context;
        this.mType = type;
    }

    @Override
    public View getView(FlowLayout parent, int position, Object o) {
        CardView cv  = (CardView) LayoutInflater.from(mContext).inflate(R.layout.item_interest_tag_flowlayout,
                null, false);
//        cv.setCardBackgroundColor(TestBean.getRandomColor());
        TextView mTextView = cv.findViewById(R.id.tv_tag_text);
        ImageView mImageView = cv.findViewById(R.id.iv_isSelected);
        IntenestTagResponBean intenestTagResponBean = (IntenestTagResponBean) o;
        mTextView.setText(intenestTagResponBean.getText());
//        mImageView.setImageResource(intenestTagResponBean.getStatus() == 0 ? R.mipmap.interest_tag_unselected : R.mipmap.interest_tag_selected);
        //ImageLoader.load(mContext, intenestTagResponBean.getStatus() == 0 ? R.mipmap.interest_tag_unselected : R.mipmap.interest_tag_selected, mImageView);
        if(mType==0){
            mImageView.setImageResource(R.mipmap.icon_add_tag);
            mTextView.setTextColor(ContextCompat.getColor(mContext,R.color.color_333));
            //可供选择
            if(intenestTagResponBean.getStatus()==0){
                cv.setVisibility(View.VISIBLE);
                cv.setCardBackgroundColor(ContextCompat.getColor(mContext,R.color.color_efefef));
            }else{
                cv.setVisibility(View.GONE);
            }
        }else{
            //已经选择列表
            mImageView.setImageResource(R.mipmap.icon_delete_tag);
            mTextView.setTextColor(ContextCompat.getColor(mContext,R.color.white));
            cv.setCardBackgroundColor(ContextCompat.getColor(mContext,R.color.colorPrimary));
        }
        return cv;
    }
}
